package ar.com.nextel.corba.server;

import java.util.Properties;

import org.omg.CORBA.ORB;
import org.omg.CosNaming.NameComponent;
import org.omg.CosNaming.NamingContext;
import org.omg.CosNaming.NamingContextHelper;

import ar.com.nextel.corba.services.PersonService;


public class ServerCorba {
	
	
	 public static void main(String args[])
	  {
	    try{
	    
	    	  // Create and initialize the ORB 
	    	Properties props = new Properties();
	        props.put("org.omg.CORBA.ORBInitialPort", "1051");
	        props.put("org.omg.CORBA.ORBInitialHost", "arpalHPd002");
	        ORB orb = ORB.init(args, props);

	        // Create the servant and register it with the ORB 
	        PersonService stockMarketImpl = new PersonService(); 
	        orb.connect(stockMarketImpl);

	        // Get the root naming context 
	        org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); 
	        NamingContext ncRef = NamingContextHelper.narrow(objRef); 
//	        NamingContextExt ncRef =NamingContextExtHelper.narrow(objRef);
	    
	        
	        
	        // Bind the object reference in naming 
//	        NameComponent name1[] = ncRef.to_name("myPersonService");
//	        ncRef.rebind(name1, objRef);
	        NameComponent nc = new NameComponent("myPersonService2", ""); 
	        NameComponent path[] = {nc}; 
	        ncRef.rebind(path, stockMarketImpl); 
	    
	        System.out.println("The StockMarket Server is up and ready...");

	        // Wait forever for current thread to die 
	        Thread.currentThread().join(); 
	      
	    } catch(Exception e) {
	        System.err.println("ERROR: " + e);
	        e.printStackTrace(System.out);
	      }  
	  }

}
